import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Bookshelf } from './bookshelf.entity';

@Injectable()
export class BookshelfService {
  constructor(
    @InjectRepository(Bookshelf)
    private readonly bookshelfRepository: Repository<Bookshelf>,
  ) { }

  async addBook(data: Partial<Bookshelf>): Promise<Bookshelf> {
    const bookshelf = this.bookshelfRepository.create(data);
    return this.bookshelfRepository.save(bookshelf);
  }

  async getBooksByUser(userId: string): Promise<Bookshelf[]> {
    return this.bookshelfRepository.find({ where: { userId } });
  }

  async removeBook(id: number): Promise<void> {
    await this.bookshelfRepository.delete(id);
  }
}
